/** Static object you add your CloudScript endpoints to */
declare var handlers: IPlayFabHandlers;
interface IPlayFabHandlers {
  [handlerId:string]: (args?:any, context?:IPlayFabContext) => any;
}

/** The playfab id for the user who called into CloudScript */
declare var currentPlayerId: string;

/**
 * Static object containing cloudscript logging functions
 * debug(message: string, exc?: any): void,
 * error(message: string, exc?: any): void,
 * info(message: string, exc?: any): void,
 */
declare var log: Logger;
interface Logger {
    debug(message: string, exc?: any): void,
    error(message: string, exc?: any): void,
    info(message: string, exc?: any): void,
}

/**
 * Static object containing cloudscript external request functions
 * request(url: string, method?: string, content?: string, contentType?: string): string
 */
declare var http: IPlayFabHttp;
interface IPlayFabHttp {
    request(url: string, method?: string, content?: string, contentType?: string, headers?: { [key: string]: string }): string
}

interface ITriggeredByTask {
    Name: string;
    Id: string;
}

interface IPlayFabContext {
    playStreamEvent: PlayStreamModels.IBasePlayStreamEvent;
    playerProfile: IPlayFabPlayerProfile;
    triggeredByTask: ITriggeredByTask;
}

interface IPlayFabPlayerProfile {
    PlayerId: string;
    DisplayName: string;
}

declare var script: IPlayFabEnvironment;
interface IPlayFabEnvironment {
    revision: number;
    titleId: string;
}

interface IPlayFabError {
    cloudScriptErrorCode : string;
    stack : string;
    apiErrorInfo?: IApiErrorInfo;
}

interface IApiErrorInfo {
    api : string;
    request : any;
    result : any;
    apiError?: IApiError;
}

interface IApiError {
    code : number;
    status : string;
    error : string;
    errorCode : number;
    errorMessage : string;
    errorDetails?: { [index:string] : { message: string[] } };
}

/** Static object which allows access to PlayFab Classic Server API calls */
declare var server: IPlayFabServerAPI;
/** Static object which allows access to PlayFab Entity API calls */
declare var entity: IPlayFabEntityAPI;
<% for(var sa in serverApiList) { var api = serverApiList[sa]; %>
/** <%- api.name %>API.Models as interfaces */
declare namespace PlayFab<%- api.name %>Models {
<% for(var i in api.datatypes) { var datatype = api.datatypes[i];
%><%- generateApiSummary("    ", datatype, "description")
%><%- makeDatatype("    ", datatype, sourceDir, "") %><% }
%>}<% } %>

/** Server interface methods */
interface IPlayFabServerAPI {
<% for(var sa in serverApiList) { var api = serverApiList[sa];
for(var i in api.calls) { var apiCall = api.calls[i];
%><%- generateApiSummary("    ", apiCall, "summary", "https://docs.microsoft.com/rest/api/playfab/" + api.name.toLowerCase() + "/" + apiCall.subgroup.toLowerCase().replaceAll(" ","-") + "/" + apiCall.name.toLowerCase()) -%>
    <%- apiCall.name %>(request: PlayFab<%- api.name %>Models.<%- apiCall.request %>): PlayFab<%- api.name %>Models.<%- apiCall.result %>;

<% } } %>
}

<% for(var ea in entityApiList) { var api = entityApiList[ea]; %>
/** <%- api.name %>API.Models as interfaces */
declare namespace PlayFab<%- api.name %>Models {
<% for(var i in api.datatypes) { var datatype = api.datatypes[i];
%><%- generateApiSummary("    ", datatype, "description")
%><%- makeDatatype("    ", datatype, sourceDir, "") %><% }
%>}<% } %>

/** Entity interface methods */
interface IPlayFabEntityAPI {
<% for(var ea in entityApiList) { var api = entityApiList[ea];
%>
<% for(var i in api.calls) { var apiCall = api.calls[i];
%><%- generateApiSummary("    ", apiCall, "summary", "https://docs.microsoft.com/rest/api/playfab/" + api.name.toLowerCase() + "/" + apiCall.subgroup.toLowerCase().replaceAll(" ","-") + "/" + apiCall.name.toLowerCase()) -%>
    <%- apiCall.name %>(request: PlayFab<%- api.name %>Models.<%- apiCall.request %>): PlayFab<%- api.name %>Models.<%- apiCall.result %>;

<% } } %>
}
